package com.xbongbong.paas.factory;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.service.field.FieldOptimizationService;
import com.xbongbong.paas.service.field.impl.AddressOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.BirthdayOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.CoUserIdOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.ComboLinkBusinessOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.ComboNumOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.ComboOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.CreatorIdOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.DateTimeOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.DefaultOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.DepartmentIdOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.DeptOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.FileOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.LinkDataMultiOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.LinkDataOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.NumOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.OwnerIdOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.SeparatorOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.SerialNoOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.SpecificationOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.SystemLinkDataOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.SystemTimeOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.TextAreaOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.TextOptimizationServiceImpl;
import com.xbongbong.paas.service.field.impl.UserOptimizationServiceImpl;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: 吴峰
 * @date: 2020/7/6 15:46
 */
public class FieldOptimizationFactory {

    /**
     * 字段优化处理器
     */
    private final static Map<Integer, FieldOptimizationService> FILED_OPTIMIZATION_HANDLE_MAP = new ConcurrentHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);



    public FieldOptimizationFactory() {
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.TEXT.getType(), new TextOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.TEXTAREA.getType(), new TextAreaOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.NUM.getType(), new NumOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.COMBO.getType(), new ComboOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.COMBO_CHECK.getType(), new ComboOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.RADIO_GROUP.getType(), new ComboOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.CHECKBOX_GROUP.getType(), new ComboOptimizationServiceImpl());
        // 下拉+关联业务选择，比如跟进记录的跟进业务
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.COMBO_LINK_BUSINESS.getType(), new ComboLinkBusinessOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.SEPARATOR.getType(), new SeparatorOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.SERIALNO.getType(), new SerialNoOptimizationServiceImpl());
        // 负责人
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.OWNERID.getType(), new OwnerIdOptimizationServiceImpl());
        // 协同人
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.COUSERID.getType(), new CoUserIdOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.USER.getType(), new UserOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.USER_GROUP.getType(), new UserOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.DEPT.getType(), new DeptOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.DEPT_GROUP.getType(), new DeptOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.DEPARTMENTID.getType(), new DepartmentIdOptimizationServiceImpl());
        // 地址
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.ADDRESS.getType(), new AddressOptimizationServiceImpl());
        // 定位
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.LOCATION.getType(), new AddressOptimizationServiceImpl());
        // 逻辑下拉（如客户是否归档）
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.COMBO_NUM.getType(), new ComboNumOptimizationServiceImpl());
        // 附件
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.UPLOAD.getType(), new FileOptimizationServiceImpl());
        // 图片
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.IMAGE.getType(), new FileOptimizationServiceImpl());
        // 关联数据
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.LINK_DATA.getType(), new LinkDataOptimizationServiceImpl());
        // 关联数据多选
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.LINK_DATA_MULTI.getType(), new LinkDataMultiOptimizationServiceImpl());
        // 日期
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.DATETIME.getType(), new DateTimeOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.ENDTIME.getType(), new DateTimeOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.CLOSETIME.getType(), new DateTimeOptimizationServiceImpl());
        // 创建时间、更新时间、创建人
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.ADDTIME.getType(), new SystemTimeOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.UPDATETIME.getType(), new SystemTimeOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.CREATORID.getType(), new CreatorIdOptimizationServiceImpl());
        // 生日
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.BIRTHDAY.getType(), new BirthdayOptimizationServiceImpl());
        // 系统关联数据-单选
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), new SystemLinkDataOptimizationServiceImpl());
        // 系统关联数据-多选
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.LINK_BUSINESS_MULTI.getType(), new SystemLinkDataOptimizationServiceImpl());
        // 规格
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.SPECIFICATION.getType(), new SpecificationOptimizationServiceImpl());
        //阶段推进器
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.STAGE_THRUSTER.getType(), new ComboOptimizationServiceImpl());
        FILED_OPTIMIZATION_HANDLE_MAP.put(FieldTypeEnum.STAGE_RATIO.getType(), new NumOptimizationServiceImpl());
    }

    public FieldOptimizationService getByFieldType(Integer fieldType) {
        FieldOptimizationService fieldOptimizationService = FILED_OPTIMIZATION_HANDLE_MAP.get(fieldType);
        if (Objects.isNull(fieldOptimizationService)) {
            return new DefaultOptimizationServiceImpl();
        }
        return fieldOptimizationService;
    }
}
